# Maintainer: George Rawlinson <grawlinson@archlinux.org>

pkgname=python-pyasn
pkgver=1.6.1
pkgrel=4
pkgdesc='Python IP address to Autonomous System Number lookup module'
arch=('loong64' 'x86_64')
url='https://github.com/hadiasghari/pyasn'
license=('MIT' 'BSD') # SPDX:BSD-4-Clause
# namcap complains about ordereddict, but this is only for Python 2
# it also complains about urllib2, let's ignore that too
depends=(
  'python'
  'python-ujson'
)
makedepends=(
  'git'
  'python-build'
  'python-installer'
  'python-wheel'
  'python-setuptools'
)
checkdepends=('python-pytest')
_commit='1d64d6d2f20e0353b46fbf5b94f8bdea8f41e9ce'
source=("$pkgname::git+$url#commit=$_commit")
b2sums=('SKIP')

pkgver() {
  cd "$pkgname"

  git describe --tags | sed -e 's/^v//' -e 's/-re$//'
}

build() {
  cd "$pkgname"

  python -m build --wheel --no-isolation
}

check() {
  cd "$pkgname"

  # temporary install so pytest can pick up the compiled extension
  python -m installer --destdir="$(pwd)/tmp" dist/*.whl
  local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")
  export PYTHONPATH="$(pwd)/tmp/$site_packages"

  pytest -v
}

package() {
  cd "$pkgname"

  python -m installer --destdir="$pkgdir" dist/*.whl

  # license
  install -vDm644 -t "$pkgdir/usr/share/licenses/$pkgname" LICENSE
}
